<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../../ass/assParking/assParkCommon.jsp" flush="true" />
<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
<div>
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">承租人名称</div>
							<div class="field">
								<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">合同号</div>
							<div class="field">
								<input type="text" id="contractNo" name="contractNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">支付表号</div>
							<div class="field">
								<input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						
						<div class="fieldBox">
							<div class="label">事业部</div>
							<div class="field">
								<select id="buOrgCd"  name="buOrgCd"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${buOrgCdList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<!--  
						<div class="fieldBox">
							<div class="label">省公司</div>
							<div class="field">
								<select id="cstMgrOrgCd"  name="cstMgrOrgCd"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${prList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						-->
						<div class="fieldBox col_33" id="cstMgrOrgCdId" >
			                <div class="label">省公司</div>
			                <div class="field">
			                    <input name="cstMgrOrgCd" id="cstMgrOrgCd" type="text" class="ui-textbox" value="">
			                </div>
		                 </div>
						<div class="fieldBox">
		                    <div class="label">放款时间</div>
		                    <div class="field">
		                        <input ligerui="width: 120" name="actPayTmB" id="actPayTmB" type="text" class="ui-datepicker" value="">
		                        -
		                        <input ligerui="width: 120" name="actPayTmE" id="actPayTmE" type="text" class="ui-datepicker" value="">
		                    </div>
	               	    </div>
						<div class="fieldBox">
							<div class="label">电子归档状态</div>
							<div class="field">
								<select id="eleStorageStatus"  name="eleStorageStatus"  ligerui="width: 160">
									<option value="1" selected>未归档</option>
									
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">纸质归档状态</div>
							<div class="field">
								<select id="storageStatus"  name="storageStatus"  ligerui="width: 160">
									<option value="1" selected>未归档</option>
									
								</select>
							</div>
						</div>
						
						
	               	    
					</div>
					
					
					<div class="clearFix"></div>
					
					<!-- 表单按钮 -->
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						<!--  
						<input id="upfile" name="upfile" style="width:150px" type="file">						
						<span id="upBtn" class="sq-button-round"  onclick="uploadExcel();">上传权证</span>
						<span>
							<a  style="color:blue;text-decoration:underline;" href="<%=path%>/resource/template/reffile/arcDZdemo.xls" />电子模板下载</a>&nbsp;&nbsp;&nbsp;&nbsp; 
		                </span>						
						<span>
							<a  style="color:blue;text-decoration:underline;" href="<%=path%>/resource/template/reffile/arcZZdemo.xls" />纸质模板下载</a>&nbsp;&nbsp;&nbsp;&nbsp; 
		                </span>
		                -->
		            </div>
		           
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>
	</div>
	
	
</div>
<script type="text/javascript">
	var pageInApp={
		flag:false //tab页验证关闭
	};//to下一级子窗口 接口
	var pageInTab=null;//页签
	var loadedTabs=[];//页签
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    initTab();//初始化页签
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/archive/arcMgrMain/initList.do?tab=b',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '承租人名称', name: 'cstNm', width: 120 , enabledSort:true},
				{ display: '合同号', name: 'contractNo', minWidth: 180 , align:'center', enabledSort:true},
				{ display: '支付表号', name: 'paySchNo', minWidth: 180 , align:'center', enabledSort:true},
			    { display: '放款时间', name: 'actPayTm', width: 120 , enabledSort:true},
					 
				{ display: '事业部', name: 'buOrgCdNm', width: 120 , enabledSort:true},
				{ display: '省公司 ', name: 'prOrgCdNm', width: 120 , enabledSort:true},
				{ display: '合同纸质归档状态', name: 'storageStatusConNm', minWidth: 100 ,  enabledSort:false},
				{ display: '权证纸质归档状态', name: 'storageStatusNm', minWidth: 100 ,  enabledSort:false},
				
				{ display: '合同电子归档状态', name: 'eleStorageStatusConNm', minWidth: 100 , enabledSort:false},		
				{ display: '权证电子归档状态', name: 'eleStorageStatusNm', minWidth: 100 , enabledSort:false},
				
				{ display: '移交状态', name: 'transferStatusNm', minWidth: 80 ,  enabledSort:false},
				{
					display:'操作',
					isSort:false,
					width:220,
					align:'left',
					render:function (rowdata, rowindex, value){
						var h="";
						//if(rowdata.storageStatus == "1" && rowdata.eleStorageStatus == "1" ){
						//	h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>查看</font>';
			                
						//}else{
		                	h+='<a class="sq-button-hasicon" href="javascript:viewDetail(';
			                h+="'"+rowdata.paySchId+"'";
			                h+=",'"+rowdata.contractNo+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>查看</a>";
		               // }
						
						if((rowdata.storageStatus == "1" && rowdata.eleStorageStatus == "1")
								&&(rowdata.transferStatus!='1' && rowdata.transferStatus!='2')){
			            	h+='<a class="sq-button-hasicon" href="javascript:warrantApply(';
			            	h+="'"+rowdata.paySchId+"'";
			                h+=",'"+rowdata.contractNo+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>归档申请</a>";
			                
						}else{
		                	h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>归档申请</font>';
		                	
		                }
						//if(rowdata.storageStatus == "1" && rowdata.eleStorageStatus == "1" ){
						//	h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>流程信息</font>';
			                
						//}else{
		                	h+='<a class="sq-button-hasicon" href="javascript:viewFlow(';
		                	h+="'"+rowdata.paySchId+"'";
			                h+=",'"+rowdata.contractNo+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>流程信息</a>";
		                //}
						return h;
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			isScroll: true,
			checkbox:false,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			//选择行事件
			onSelectRow: function(rowdata, rowid, rowobj){
				//设置当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val(rowdata.id);
				$("#tcMasterId").val(rowdata.masterId);
			},
			//取消选择行事件
			onUnSelectRow : function(rowdata, rowid, rowobj){
				//清空当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val('');
				$("#tcMasterId").val('');
			}
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		//grid.options.isSingleCheck = true;//列表是否为单选
	}
	
	//发起申请
	function warrantApply(paySchId,contractNo){
		//回调刷新列表
		var url = '<%=path%>/archive/arcMgrMain/addFlow.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		$.ajax({
			type: 'post',
			dataType:'json',
			url: url,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在发起流程...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					//$.ligerDialog.SQalert(msg.info);
					grid.reload();
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
		
	}
	//查看详情
	function viewDetail(paySchId,contractNo){
		//回调刷新列表
		var param = '<%=path%>/archive/arcMgrMain/viewDetail.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		
		Add_navTab('warrantApply'+paySchId,'查看详情',param, function () {
			//grid.reload();
		});
	}
	//查看流程
	function viewFlow(paySchId,contractNo){
		//回调刷新列表
		var param = '<%=path%>/archive/arcApplyMain/toViewFlow.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		
		Add_navTab('toViewFlow'+paySchId,'查看流程',param, function () {
			grid.reload();
		});
	}
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			/* onBeforeSelectTabItem: function (tabid) {
				//获取客户ID供其它页面使用
				var _cId = $("#cId").val();
				if(tabid!="tabA" && !_cId){
					if(pageInApp.flag){
						$.ligerDialog.SQalert({content: LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
						return false;
					}
				}
			}, */
			onAfterSelectTabItem: function(tabid) {
				//if (loadedTabs.indexOf(tabid)<0) {//只加载一次
					
					//loadedTabs.push(tabid);
					switch (tabid){
					case "tabA":							
						pageInTab.setTabItemSrc(tabid, "<%=path%>/archive/arcMgrMain/toListPage.do?tab=a");
					break;
					case "tabB":							
						pageInTab.setTabItemSrc(tabid, "<%=path%>/archive/arcMgrMain/toListPage.do?tab=b");
						break;
					}
				//};
				SetIframe_height();
			}
		});
		//设置页签
		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"cstNm":"",
				"contractNo":"",
				"paySchNo":"",
				"buOrgCd":"",
				"actPayTmB":"",
				"actPayTmE":"",
				"cstMgrOrgCd":""
			});
			searchOrgTree.setValue('');//清空树
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//查看支付表详情
	function payDetail(id){
		var editFlag = true;
		Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toPrjPrdPaySchMDetailPage.do?id='+id+'&detailFlag='+editFlag);
	}
	
	//拖车申请
	function trailCarApply(paySchId,paySchNo){
		Add_navTab('trailCar'+paySchId,'拖车申请','<%=path%>/ass/assTrailCarD/toApplyPage.do?paySchId='+paySchId+'&paySchNo='+paySchNo);
	}
	

	//导出信息
	function downloadBtnEvent(){
		var form = new liger.get("searchBar");
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		var pkIds = new Array();
		for(var i=0;i<selectedRows.length;i++){
			var pkId = "'"+selectedRows[i].paySchId+"'";
			pkIds[i] = pkId;
		}
        var data = form.getData();
        data["pkIds"] = JSON.stringify(pkIds);
        data["eFlag"] = "tcgl";
		var wait_dialog = null;
		$.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/ass/assTrailCarM/exportAssInfo.do',
			data:data,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在导出信息...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
	var searchOrgTree;
	
	initOrgTree();
	function initOrgTree(){
    	var params = {};
    	 searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
    		 width: 480,
             selectBoxWidth: 480,
             selectBoxHeight: 150,
             //限制只能选叶节点，父节点不能点击
             treeLeafOnly: false,
             valueField: 'orgCd',
             textField: 'orgDispNm',
             showTreePath: true,
             tree: {
                 ajaxType: 'get',
                 idFieldName:'orgCd',
                 textFieldName: 'orgDispNm',
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none",
                 needCancel : false
             }
         });
    	 $.ajax({
     		type: 'get',
     		dataType:'json',
     		data: params,
     		url: '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do',
     		success:function(msg){
     			if(msg.success == 1){
     				searchOrgTree.treeManager.setData(msg.data);
     				searchOrgTree.clear();
     				searchOrgTree.setValue('${currOrg}');
     			}else{
     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     			}
     		}
     	});

    }    
</script>
<script type="text/javascript">
//上传权证
function uploadExcel(){ 
	var wait_dialog=$.ligerDialog.SQalert({content: '上传中,请稍后...' ,SQ_type: "waitting" });
	$.ajaxFileUpload({  
		
	    url : "<%=path%>/archive/arcMgrMain/importPay.do",  
	    dataType : 'json',  
	    data : {},
	    secureuri : false,  
	    fileElementId :'upfile',
	    success : function(msg) { //服务器成功响应处理函数  
	    	wait_dialog.close();
	    	 if(msg.success == 1){
		    	//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
		    	$.ligerDialog.SQalert(msg.info);
//			    	
			 }else{
				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }  
        },error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		}   
    });  
}

</script>
</body>
</html>